package com.gxuwz.com_property.role.controller;

import com.gxuwz.com_property.common.dto.ResponseDto;
import com.gxuwz.com_property.menu.pojo.Menu;
import com.gxuwz.com_property.repair.service.RepairService;
import com.gxuwz.com_property.role.pojo.Role;
import com.gxuwz.com_property.role.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class RoleCotroller {
    @Autowired
    private RoleService roleService;

    @PostMapping("/addRole")
    private ResponseDto addRoleManeage(@RequestBody Role role){
        boolean addRoleboolean = roleService.addRole(role);

        if (addRoleboolean){
            return ResponseDto.success("角色添加成功");
        }else {
            return ResponseDto.error("角色添加失败");
        }

    }

    @PostMapping("/updateRole")
    private ResponseDto updateRoleManeage(@RequestBody Role role){
        boolean updateRoleboolean = roleService.updateRoleById(role);

        if (updateRoleboolean){
            return ResponseDto.success("角色修改成功");
        }else {
            return ResponseDto.error("角色修改失败");
        }

    }

    @PostMapping("/delectRole")
    private ResponseDto delectRoleManeage(@RequestBody int id){
        boolean delectRoleboolean = roleService.delectRoleById(id);

        if (delectRoleboolean){
            return ResponseDto.success("角色删除成功");
        }else {
            return ResponseDto.error("角色删除失败");
        }

    }

    @PostMapping("/selectRoleById")
    private ResponseDto selectRoleById(@RequestBody Role role){

        Role roleById = roleService.findRoleById(role);

        if (roleById!=null){
            return ResponseDto.success("查询角色成功",roleById);
        }else {
            return ResponseDto.error("查询角色失败");
        }

    }

    @PostMapping("/fingAllRoleManeage")
    private ResponseDto fingAllRoleManeage(){

        List<Role> allRole = roleService.findAllRole();
        if (allRole!=null){
            return ResponseDto.success("查询角色成功",allRole);
        }else {
            return ResponseDto.error("查询角色失败");
        }

    }
}
